import axios from 'axios';
import { IParams, IAjaxData } from "@/types/types";
export default (
  url: string,
  method: string,
  params?: IParams | {}
): Promise<any> => {
  return new Promise((resolve: Function, reject: Function) => {
    if (method == "GET") {
      axios
        .get(url, {
          params: params,
        })
        .then(({ data }: IAjaxData) => {
          resolve(data);
        })
        .catch((err: Error) => {
          reject(err);
        });
    } else if (method == "POST") {
      axios
        .post(url, params)
        .then(({ data }: IAjaxData) => {
          resolve(data);
        })
        .catch((err: Error) => {
          reject(err);
        });
    }
  });
};
